/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package traffic.light.simulator.town.unity;

/**
 *
 * 
 */
class TownUnityType5 extends TownUnity {

    public TownUnityType5(int positionX, int positionY, int townSize) {
        super(CrossRoadType.TYPE_5, positionX, positionY, townSize);
    }

    @Override
    public void generateCorrespondantUnity() {
        super.generateCorrespondantUnity();
        
        townElements[0][2] = new RoadElement(absoluteElementXPosition(2), absoluteElementYPosition(0), RoadType.DOWN);
        townElements[0][3] = new RoadElement(absoluteElementXPosition(3), absoluteElementYPosition(0), RoadType.UP);
        townElements[1][2] = new RoadElement(absoluteElementXPosition(2), absoluteElementYPosition(1), RoadType.DOWN);
        townElements[1][3] = new RoadElement(absoluteElementXPosition(3), absoluteElementYPosition(1), RoadType.UP);
        townElements[2][2] = new RoadElement(absoluteElementXPosition(2), absoluteElementYPosition(2), RoadType.DOWN);
        townElements[2][3] = new RoadElement(absoluteElementXPosition(3), absoluteElementYPosition(2), RoadType.UP_AND_LEFT);
        townElements[2][4] = new RoadElement(absoluteElementXPosition(4), absoluteElementYPosition(2), RoadType.LEFT);
        townElements[2][5] = new RoadElement(absoluteElementXPosition(5), absoluteElementYPosition(2), RoadType.LEFT);
        townElements[3][2] = new RoadElement(absoluteElementXPosition(2), absoluteElementYPosition(3), RoadType.DOWN_AND_RIGHT);
        townElements[3][3] = new RoadElement(absoluteElementXPosition(3), absoluteElementYPosition(3), RoadType.UP_AND_RIGHT);
        townElements[3][4] = new RoadElement(absoluteElementXPosition(4), absoluteElementYPosition(3), RoadType.RIGHT);
        townElements[3][5] = new RoadElement(absoluteElementXPosition(5), absoluteElementYPosition(3), RoadType.RIGHT);
        townElements[4][2] = new RoadElement(absoluteElementXPosition(2), absoluteElementYPosition(4), RoadType.DOWN);
        townElements[4][3] = new RoadElement(absoluteElementXPosition(3), absoluteElementYPosition(4), RoadType.UP);
        townElements[5][2] = new RoadElement(absoluteElementXPosition(2), absoluteElementYPosition(5), RoadType.DOWN);
        townElements[5][3] = new RoadElement(absoluteElementXPosition(3), absoluteElementYPosition(5), RoadType.UP);
        generateAccessibleElements();
        generateTL();
    }

    @Override
    protected void generateAccessibleElements() {
        if (positionX == townSize - 1 || positionY == townSize - 1 || positionY == 0) {
            this.isAccessibleForMovableEntities = true;

            if (positionY == 0) {
                this.accessibleTownElement = townElements[0][2];
            } else if (positionY == townSize - 1) {
                this.accessibleTownElement = townElements[5][3];
            } else if (positionX == townSize - 1) {
                this.accessibleTownElement = townElements[2][5];
            }
        }
    }
}
